/**
 * 
 * @param {*} success -连接成功的回调
 */

module.exports = function (success) {
    const mongoose = require('mongoose');
    const config = require('../config/config');
    // 设置strictQuery
    mongoose.set('strictQuery', true);
    mongoose.connect(`mongodb://${config.DBHOST}:${config.DBPORT}/${config.DBNAME}`).then(success);
    // 设置回调once只执行一次
    // mongoose.connection.once('open', () => {
    //     success();
    // });
    // mongoose.connection.on('error',()=>{
    //     error();
    // })
    // 关闭数据库
    // mongoose.disconnect();
    mongoose.connection.on('close', () => {
    });
};